<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Store into cache</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.yac.html">« Yac</a></li>
      <li style="float: right;"><a href="yac.construct.html">Yac::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.yac.html">Yac</a></li>
    <li>Store into cache</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="yac.add" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Yac::add</h1>
  <p class="verinfo">(PECL yac &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Yac::add</span> &mdash; <span class="dc-title">Store into cache</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yac.add-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Yac::add</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$keys</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$ttl</code><span class="initializer"> = 0</span></span>): <span class="type">bool</span></div>

  <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><strong>Yac::add</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$key_vals</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
    Added a item into cache.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-yac.add-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">keys</code></dt>

    <dd>

     <p class="para">
       <span class="type">string</span> key
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">value</code></dt>

    <dd>

     <p class="para">
      mixed value, All php value type could be stored except <a href="language.types.resource.html" class="link">资源(resource)</a>
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">ttl</code></dt>

    <dd>

     <p class="para">
      expire time
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-yac.add-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="type">bool</span>, <strong><code>true</code></strong> on success, <strong><code>false</code></strong> on failure 
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <p class="para">
     <span class="methodname"><strong>Yac::add()</strong></span> may fail if cas lock could not obtain,
     so, if you need the value to be stored properly, you may write codes like:
     <div class="example" id="example-684">
      <p><strong>示例 #1 Make sure the item is stored</strong></p>
      <div class="example-contents">
       <div class="phpcode"><code><span style="color: #000000">
while(!$yac-&gt;set("key",&nbsp;"vale));</span>
</code></div>
      </div>
 
     </div>
    </p>
   </p></blockquote>
  </p>
 </div>



</div></div></div></body></html>